import { defineStore } from "pinia";

export const useCountStore = defineStore("count", {
  state: () => {
    return {
      sum: 0,
      school: 'qinghua',
      address: '地址'
    };
  },
  getters: {
    // 写法一 使用state
    bigSum (state) {
      return state.sum * 10
    },
    // 方法一可以简写为
    bigSum2: state => state.sum * 20,
    // 写法二 使用this
    toUpperSchool (state) {
      return this.school.toUpperCase()
    },
    // 方法二可以简写为
    toUpperSchool2 ():string {
      return this.school.toUpperCase()
    }
  },
  actions: {
    increment(value) {
      console.log('increment调用了', this)
      if (this.sum < 10) {
        this.sum += value;
      }
    },
    decrement(value) {
      if (this.sum > 0) {
        this.sum -= value
      }
    }
  },
});
